package List;

import day01.Student;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/4/28
 */
public class UserTest2 {
    public static void main(String[] args) {
        User user1 = new User("aaa","111");
        User user2 = new User("bbb","222");
        User user3 = new User("ccc","333");
        User user4 = new User("ddd","444");
        User user5 = new User("eee","555");
        List<User> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);
        list.add(user3);
        list.add(user4);
        list.add(user5);
        contains(list);

    }
    public static void contains(List<User> list){
        boolean flag = false;
        Scanner sc = new Scanner(System.in);
        int count=3;
        while (count>0) {
            System.out.println("请输入用户名：");
            String name=sc.nextLine();
            System.out.println("请输入密码：");
            String password=sc.nextLine();
            for (User user : list) {
                if (user.getPassword().equals(password)&&user.getUserName().equals(name)) {
                    System.out.println("登录成功！");
                    flag = true;
                    count=0;
                    break;
                }
            }
            if (flag) {
                break;
            }
            count--;
            if(count==0){
                System.out.println("您的登录次数已用完！");
                break;
            }else{
                System.out.println("用户名或密码错误，请重新输入！");
            }
        }
    }
}
